<?php

namespace app\admin\command;

use app\admin\model\CompanyOrderModel;
use app\admin\model\GoodsOrderModel;
use app\admin\model\MemberModel;
use app\admin\model\RechargeRecord;
use app\admin\model\StatisticsHomeModel;
use app\admin\model\StatisticsModel;
use app\admin\service\CommandService;
use app\api\model\SpecialOrder;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\Db;
use function form\e;

/***
 * 数据统计 20分钟一次
 */
class StatisticsHome extends Command
{

    protected function configure()
    {
        // 指令配置
        $this->setName('StatisticsHome');
        $this->addArgument("date", Argument::OPTIONAL, "date")
            ->setHelp("php think StatisticsHome [date]");
        // 设置参数
//        $this->setDescription('数据统计')->setHelp("php think Statistics");
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln('开始执行');
        $total = (new StatisticsModel())
            ->field('SUM(total_amount) as total_amount,
            SUM(spec_amount) as spec_amount, SUM(package_amount) as package_amount,SUM(goods_amount) as goods_amount,SUM(vip_amount) as vip_amount')
            ->find()->toArray();
       //查询平台总用户
        $total['total_user'] = (new MemberModel())->count();
        $total['update_time'] = time();
        (new StatisticsHomeModel())->where(['id' => 1])->update($total);

        $output->writeln('执行结束');
    }


}